package org.wii.learner;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import android.content.ContentValues;
import android.content.Context;
import android.view.*;
import android.view.View.OnClickListener;
import android.widget.*;

import org.wii.learner.ConsumedDB;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;

public class MyOnSubmitListener implements OnClickListener{
	
	private EditText edtext;
	private Spinner spinner;
	private ConsumedDB database;
	
	public MyOnSubmitListener(EditText a, Spinner b, ConsumedDB c){
		edtext=a;
		spinner=b;
		database=c;

	}
      
    public void onNothingSelected(AdapterView<?> parent) {
          // Do nothing.
    }
    
    public void onClick(View v) {
    	// This code gets the current date
  	
       Calendar calendar = Calendar.getInstance();
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
        String nowDate = dateFormat.format(calendar.getTime());
        
        // This code gets the value from the edit text field where people can type in the name
        String nameVeggie = edtext.getText( ).toString( );
        
        // This code gets the current value of the spinner
        String numVeggie = (String) spinner.getSelectedItem();
        
        // This code will create key, value pairs to be passed into the database, then inserts them
        
            
        final SQLiteDatabase db = database.getWritableDatabase();

        ContentValues vals = new ContentValues();
        vals.put("date", nowDate);
        vals.put("name", nameVeggie);
        vals.put("numberOf", numVeggie);
        db.insert("veggies", null, vals); 

    }  
			
}

